package com.wifiscanner;

import android.app.ListActivity;
import android.content.Context;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;

import com.wifiscanner.DBAdapter.AccessPointCursor;

public class ListViewActivity extends ListActivity {
	
	TextView mainText;
	WifiManager mainWifi;
	DBAdapter db;
	
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listview_layout);
        
      mainWifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
      db = new DBAdapter(this);
	  db.open();
           
      String[] srcfields = new String[] {
    		  "_id", "ssid",
    		  "capabilities","level",
			"frequency",
			"lat","lon","alt",
			"timestamp"
      };
      
      int[] dstfields = new int[] {
    		 R.id.fbssid, R.id.fssid,    	     
    		 R.id.fcapabilities,R.id.flevel,
    		 R.id.ffrequency,
    		 R.id.flat,R.id.flon,R.id.falt,
    		 R.id.ftimestamp
       }; 
 
      AccessPointCursor cursor = db.getAccessPoints(null, null);
      startManagingCursor(cursor);
          
      SimpleCursorAdapter adapter = new SimpleCursorAdapter(
  			this,
  			R.layout.listview_row,
  			cursor,
  			srcfields,
  	        dstfields);
          
          setListAdapter(adapter);
	}
	
	protected void onDestroy() {
		db.close();
	    super.onDestroy();
	}
	
}
